﻿
Namespace LightSwitchApplication

    Public Class ConsultationPreNatal

        Private myDialogHelper As ModalWindow
        Private myDialogHelperPreviousPregnancy As ModalWindow
        Private myDialogHelperPreNatalVisit As ModalWindow

#Region " - main methods - "
        Private Sub ConsultationPreNatal_InitializeDataWorkspace(saveChangesTo As System.Collections.Generic.List(Of Microsoft.LightSwitch.IDataService))
            ' Write your code here.
            If Not PatientNo = Nothing Then
                Me.PatientProperty = Me.Patient
                Me.DisplayName = "PreNatal - " & Me.Patient.SummaryName
            Else
                Me.PatientProperty = New Patient()
            End If
            Me.ScreenHeader = "PreNatal Details"
            Me.strCurrentPregnancy = "Current Pregnancy"


            myDialogHelper = New ModalWindow(Me.Pregnancies, "NewPregnancyPopup")
            myDialogHelperPreviousPregnancy = New ModalWindow(Me.PreviousPregnancies, "PreviousPregnancyModal")
            myDialogHelperPreNatalVisit = New ModalWindow(Me.PrenatalVisits, "PreNatalVisitModal")

            If Not Me.Pregnancies.SelectedItem Is Nothing Then
                Me.paramPregnancyNo = Me.Pregnancies.SelectedItem.pregnancyno
            End If
        End Sub

        Private Sub ConsultationPreNatal_Saved()
            ' Write your code here.
            'Me.Close(False)
            'Application.Current.ShowDefaultScreen(Me.PatientProperty)
            setPregnancyRecordButtons()
            Me.Refresh()

        End Sub

        Private Sub btnStartNewPregnancyMethod_Execute()
            ' Write your code here.

        End Sub
#End Region

#Region " - common methods - "
        Private Sub setPregnancyRecordButtons()
            If Me.Pregnancies.Count = 0 Then
                Me.FindControl("startPregnancyMethod").IsEnabled = True
                Me.FindControl("ConcludePregnancyMethod").IsEnabled = False
            Else
                Me.FindControl("startPregnancyMethod").IsEnabled = False
                Me.FindControl("ConcludePregnancyMethod").IsEnabled = True
                'Pregnancies_AddAndEditNew()
            End If
        End Sub

#End Region

#Region " - screen events - "
        Private Sub ConsultationPreNatal_Created()
            ' Write your code here.
            myDialogHelper.Initialise()
            myDialogHelperPreviousPregnancy.Initialise()
            myDialogHelperPreNatalVisit.Initialise()
            'set button status
            setPregnancyRecordButtons()
            

            If Me.Pregnancies.SelectedItem Is Nothing Then
                Me.FindControl("PreNatalVisitbyPregnancyNoAddAndEditNew").IsEnabled = False
                Me.FindControl("PreNatalVisitbyPregnancyNoEditSelected").IsEnabled = False
                Me.FindControl("PreNatalVisitbyPregnancyNo_DeleteSelected").IsEnabled = False
            Else
                Me.FindControl("PreNatalVisitbyPregnancyNoAddAndEditNew").IsEnabled = True
                Me.FindControl("PreNatalVisitbyPregnancyNoEditSelected").IsEnabled = True
                Me.FindControl("PreNatalVisitbyPregnancyNo_DeleteSelected").IsEnabled = True
            End If
        End Sub
#End Region

#Region " - control events - "
        Private Sub startPregnancyMethod_Execute()
            ' Write your code here.
            myDialogHelper.AddEntity()
            setPregnancyRecordButtons()
        End Sub

        Private Sub ConcludePregnancyMethod_Execute()
            ' Write your code here.
            Me.Pregnancies.SelectedItem.closePregnancy = True
            myDialogHelperPreviousPregnancy.AddEntity()
            setPregnancyRecordButtons()
        End Sub
#End Region

#Region " - current pregnancy modal window  - "
        Private Sub OKModalMethod_Execute()
            ' Write your code here.
            myDialogHelper.DialogOk()
            ShowMessageBox("Click on SAVE to activate Prenatal Visit record.", "Pregnancy", MessageBoxOption.Ok)
        End Sub

        Private Sub CancelModalMethod_Execute()
            ' Write your code here.
            myDialogHelper.DialogCancel()
        End Sub
#End Region

#Region " - previous pregnancy modal window - "
        Private Sub OkPreviousPregnancyMethod_Execute()
            ' Write your code here.
            If Not Me.Pregnancies.SelectedItem Is Nothing Then
                Me.PreviousPregnancies.SelectedItem.PregnancyNo = Me.Pregnancies.SelectedItem.pregnancyno
            End If
            myDialogHelperPreviousPregnancy.DialogOk()
        End Sub

        Private Sub CancelPreviousPregnancyMethod_Execute()
            ' Write your code here.
            myDialogHelperPreviousPregnancy.DialogCancel()
        End Sub
#End Region


#Region " - prenatal visits Add/Edit/Delete buttons - "

        Private Sub PreNatalVisitbyPregnancyNoAddAndEditNew_CanExecute(ByRef result As Boolean)
            ' Write your code here.
            result = myDialogHelperPreNatalVisit.CanAdd
        End Sub

        Private Sub PreNatalVisitbyPregnancyNoAddAndEditNew_Execute()
            ' Write your code here.
            Me.paramPregnancyNo = Me.Pregnancies.SelectedItem.pregnancyno
            myDialogHelperPreNatalVisit.AddEntity()
        End Sub

        Private Sub PreNatalVisitbyPregnancyNoEditSelected_CanExecute(ByRef result As Boolean)
            ' Write your code here.
            result = myDialogHelperPreNatalVisit.CanView
        End Sub

        Private Sub PreNatalVisitbyPregnancyNoEditSelected_Execute()
            ' Write your code here.
            myDialogHelperPreNatalVisit.ViewEntity()
        End Sub

#End Region

#Region " - prenatal visits modal window - "
        Private Sub OkPrenatalVisitMethod_Execute()
            ' Write your code here.           
            Me.PrenatalVisits.SelectedItem.PregnancyNo = Me.Pregnancies.SelectedItem.pregnancyno
            myDialogHelperPreNatalVisit.DialogOk()
        End Sub
        Private Sub CancelPrenatalVisitMethod_Execute()
            ' Write your code here.
            myDialogHelperPreNatalVisit.DialogCancel()
        End Sub
#End Region


        Private Sub PreviousPMethod_Execute()
            ' Write your code here.
            Me.Application.ShowPatientPreviousPregnancy(Me.PatientNo)
        End Sub
    End Class

End Namespace